﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utilities;
using InfoSoftGlobal;

public partial class RiskStatus : System.Web.UI.Page 
{
    private struct _RiskStatus
    {
        public string UserName;
        public int Active;
        public int Postponed;
        public int Closed;
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        FCLiteral.Text = CreateDeliverableStatusChart();
        
    }

    public string CreateDeliverableStatusChart()
    {
        string sqlCon = System.Configuration.ConfigurationManager.ConnectionStrings["FastSharePoint"].ConnectionString;

        System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(sqlCon);
        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetRiskStatusByUser", con);

        cmd.CommandType = System.Data.CommandType.StoredProcedure;

        con.Open();

        System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
        System.Collections.ArrayList Risks = new System.Collections.ArrayList();

        while (dr.Read())
        {
            _RiskStatus risk = new _RiskStatus();
            risk.UserName = (string)dr["UserName"];
            risk.Active = (int)dr["Active"];
            risk.Postponed = (int)dr["Postponed"];
            risk.Closed = (int)dr["Closed"];


            Risks.Add(risk);
        }

        con.Close();

        string strXML; string strXML1; string strXML2; string strXML3; string strXML4; int i;

        //strXML = "<graph caption='Breakdown of Project Status' subCaption='(into Products and Services)' xAxisName='Project' yAxisMaxValue='5' numberSuffix='%' areaBorderColor='FFFFFF' showValues='0' numVDivLines='6' palette='5'>";
        strXML = "<graph caption='Breakdown of Risks' subCaption='(By User)' xAxisName='Projects' yAxisMaxValue='" + Risks.Count.ToString() + "' decimalPrecision='0' areaBorderColor='FFFFFF' showValues='0' numVDivLines='5' palette='5'>";
        strXML1 = "<categories>";
        strXML2 = "<dataset seriesName='Active' color='999999'>";
        strXML3 = "<dataset seriesName='Resolved' color='0099FF'>";
        strXML4 = "<dataset seriesName='Closed' color='006F00'>";


        for (i = 0; i < Risks.Count; i++)
        {
            _RiskStatus Risk = (_RiskStatus)Risks[i];
            strXML1 += "<category name='" + Risk.UserName + "' />";
            strXML2 += "<set value='" + Risk.Active.ToString() + "' />";
            strXML3 += "<set value='" + Risk.Postponed.ToString() + "' />";
            strXML4 += "<set value='" + Risk.Closed.ToString() + "' />";
        }

        strXML1 += "</categories>";
        strXML2 += "</dataset>";
        strXML3 += "</dataset>";
        strXML4 += "</dataset>";


        strXML += strXML1;
        strXML += strXML2;
        strXML += strXML3;
        strXML += strXML4;

        strXML += "</graph>";

        //Create the chart - Column 3D Chart with data contained in strXML
        return FusionCharts.RenderChart("../FusionCharts/FCF_StackedColumn3D.swf", "", strXML, "productSales", "450", "300", false, false);


    }


}
